'''
CheckButton复选按钮
可以显示文本和图像
Canvas画布
是一个矩形区域，可以放置图像组件等
'''
from tkinter import *

class Application(Frame):

    def __init__(self, master=None):
        super().__init__(master)
        self.master = master
        self.pack()
        self.create_widgets()

    def create_widgets(self):
        self.canvas = Canvas(self,width=300, height=200, bg='green')
        self.canvas.pack()
        # 画直线
        line1 = self.canvas.create_line(0,0, 10,10, 20,20)
        # 画一个矩形
        rect1 = self.canvas.create_rectangle(0,0,50,50,fill='red')
        # 画一个椭圆，坐标有两队，一个为左上角一个为右下角
        oval1 = self.canvas.create_oval(0,0,50,50,fill='red')

        Button(self,text = "画十个矩形", command = self.darwrect).pack()


    def darwrect(self):
        k = 10
        l = 20
        for i in range(0,11):
            x1 = k
            x2 = k+30
            y1 = l
            y2 = l+40
            k += 10
            l += 10
            self.canvas.create_rectangle(x1,y1,x2,y2)
root = Tk()
root.geometry("400x300")
app = Application(master=root)
app.mainloop()